#include "syscall.h"

char buf[200];
int len = 0;

void print(int x) {
        int num = 1;
        int t = x/10;
        int i;
        char a[11];
        while (t) {
                num++;
                t /= 10;
        }
        for(i = 1; i <= num; i++) {
                a[num-i] = (x%10) + '0';
                x /= 10;
        }
        for(i = 0; i < num; i++) {
                buf[len++] = a[i];
        }
/*      Write(a, num, ConsoleOutput); */
}

void prints(char *a) {
        int i;
        for(i = 0; a[i]; i++)
                buf[len++] = a[i];
        if (buf[len-1] == '\n') {
                Write(buf,len,ConsoleOutput);
                len = 0;
        }
}

int main() {
        int lock;
        int mv;
        int cv1;
        int cv2;
        int k;
        lock = CreateLock("lock", 4);
        cv1 = CreateCondition("cv1", 3);
        cv2 = CreateCondition("cv2", 3);
        mv = CreateMonitor("mv", 2, 1);
        Acquire(lock);
        k = ReadMonitor(mv, 0);
        if (k < 10) {
                Wait(cv2, lock);
        }
        Broadcast(cv1, lock);
        Release(lock);
        Exit(0);
}